<!--父级页面:所有页面(除登录页)共有的左侧与顶部条-->
<!--对应应聘记录-->
<template>
  <div class="page-container">
    <el-header class="fixed-header">
      <el-menu>
        <!-- 顶部条的菜单栏  -->
        <el-row style="padding-top:10px;">
          <el-col :span="2"></el-col>
          <el-col :span="1" style="display: flex; justify-content: center;padding-bottom: 15px;">
            <!-- <el-avatar>是把图片裁成圆的 -->
            <el-avatar src="/imgs/home/logo.png" style="width: 35px; height: 35px;"></el-avatar>
          </el-col>
          <el-col :span="2" style="color: #000; justify-content: center; font-weight: bold; text-align: center; display: flex; align-items: center;padding-bottom: 15px;">
            <span style="text-align: center">招财蛙</span>
          </el-col>
          <el-col :span="6" style="display: flex; justify-content: center;">
            <!--              <a :href="resume">我的简历</a>-->
            <a :href="candidateRecords" class="menu-link">我的招聘</a>
            <a :href="interestedJobs" class="menu-link">感兴趣岗位</a>
          </el-col>
        </el-row>
      </el-menu>
    </el-header>
    <!--可滚动区域      -->
    <div class="scroll-container">
      <el-main style="padding: 20px;">
        <el-row>
          <img src="/imgs/home/picture1.png" style="width: 1456px; height: 310px;">
          <div class="job-card" :data="myJob">
            <!-- 左侧职位信息区域 -->
            <div class="job-info">
              <h3 class="job-title">{{ myJob.title }}</h3>
              <p class="salary_range">{{ myJob.salaryRange }}</p>
              <p class="experience">
                {{ myJob.experience }} / {{ myJob.education }}
              </p>
              <ul class="welfare-list">
                <li v-for="(welfareList, index) in myJob.welfareList" :key="index">
                  {{ welfareList }}
                </li>
              </ul>
              <div class="publish-info">
                <span class="publish-label">发布日期</span>
                <span class="postTime">{{  myJob.postTime ? new Date(myJob.postTime).toLocaleDateString() : '' }}</span>
              </div>
            </div>
            <!-- 右侧公司及联系人信息区域 -->
            <div class="company-info">
              <img :src="myJob.companyLogo" alt="公司logo" class="company-logo" />
              <div class="company-detail">
                <h4 class="company-name">{{ myJob.companyName }}</h4>
                <p class="industry">{{ myJob.industry }}</p>
                <div class="contact-info">
                  <img :src="myJob.contactAvatar" alt="联系人头像" class="contact-avatar" />
                  <span class="contact-name">{{ myJob.contactName }}</span>
                  <span class="contact-phone">{{ myJob.contactPhone }}</span>
                </div>
              </div>
<!--              <button class="apply-button">{{ myJob.applyButtonText }}</button>-->
            </div>
          </div>

        </el-row>
        <div class="block" style="padding-top: 20px;width: 200px;  margin: 0 auto;">
          <el-timeline>
            <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :icon="activity.icon"
                :type="activity.type"
                :color="activity.color"
                :size="activity.size"
                :timestamp="activity.timestamp">
              {{activity.content}}
            </el-timeline-item>
          </el-timeline>
        </div>
      </el-main>
      <el-footer class="custom-footer" style="background: #f5f7fa" padding="20px">
        <el-row :gutter="20">
          <!-- 用户帮助区块 -->
          <el-col :xs="24" :sm="8" :md="8" class="footer-section">
            <div class="footer-title">用户帮助</div>
            <ul class="help-list">
              <!-- 使用数据驱动方式渲染帮助链接 -->
              <li v-for="(item, index) in helpLinks" :key="index">
                <el-link :href="item.url" type="info">{{ item.title }}</el-link>
              </li>
            </ul>
          </el-col>

          <!-- 联系方式区块 -->
          <el-col :xs="24" :sm="8" :md="8" class="footer-section">
            <div class="footer-title">联系我们</div>
            <div class="contact-info">
              <p>📞 客服电话：{{ contactInfo.phone }}</p>
              <p>📧 企业邮箱：
                <el-link :href="`mailto:${contactInfo.email}`" type="info">
                  {{ contactInfo.email }}
                </el-link>
              </p>
              <p>📍 公司地址：{{ contactInfo.address }}</p>
            </div>
          </el-col>

          <!-- 二维码区块 -->
          <el-col :xs="24" :sm="8" :md="8" class="footer-section qr-codes">
            <div class="footer-title">关注我们</div>
            <el-row :gutter="10">
              <el-col
                  v-for="(qr, index) in qrCodes"
                  :key="index"
                  :span="12"
                  class="qr-item"
              >
                <img :src="qr.image" :alt="qr.title" class="qr-image">
                <p class="qr-desc">{{ qr.title }}</p>
              </el-col>
            </el-row>
          </el-col>
        </el-row>

        <!-- 版权信息 -->
        <div class="copyright">
          <hr class="footer-divider">
          <p>© 2023 Your Company. All rights reserved. | 备案号：京ICP备12345678号</p>
        </div>
      </el-footer>
    </div>
  </div>
</template>

<script setup>
import router from "@/router";
import {onMounted, ref,watch} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

const candidateRecords=ref('http://localhost:9090/candidateRecords')
const interestedJobs=ref('http://localhost:9090/interestedJobs')

// const BASE_URL=ref('http://localhost:9099')
// 模拟招聘信息数据，实际可从接口获取
/*const job = ref({
  companyLogo: '/imgs/companyLogo.png',
  contactAvatar: '/imgs/contactAvatar.png',// 实际替换为联系人头像地址
  applyButtonText: '应聘记录',
  title: '高级UI产品设计师（深圳）',
  salary_range: '7K-13K',
  experience: '经验3-5年',
  education: '学历不限',
  welfares: ['年终奖', '双休', '定期体检'],
  postTime: '2018年11月24日',
  companyName: '京东数科',
  industry: 'IT通信/电子/互联网',
  contactName: '马克',
  contactPhone: '13710587130'
});*/
//获取当前登录的用户信息
const user = ref(getUser());
// 获取跳转的岗位id
const jobId = ref(getJobId());

// 定义数组用来保存具体岗位数据
const myJob = ref([]);
// 后端返回的状态码（0: 已投递, 1: 被查看, 2: 已邀请）
const backendStatus = ref(0); // 初始状态

// 状态映射配置
const statusConfig = [
  { content: '已投递', type: 'primary' },
  { content: '被查看', type: 'primary' },
  { content: '已邀请', type: 'primary' },
  { content: '发放offer', type: 'primary' },
  { content: '到岗试工', type: 'primary' },
  { content: '正式入职', type: 'primary' },
];
// 定义数组用来保存时间戳的数据
const activities = ref([
  {
    content: '已投递',
    timestamp: '2018-04-03 20:46',
    type:'info'
  },
  {
    content: '被查看',
    timestamp: '2018-04-03 20:46',
    type:'info'
  },
  {
    content: '已邀请',
    timestamp: '2018-04-03 20:46',
    type:'info'
  },
  {
    content: '发放offer',
    timestamp: '2018-04-03 20:46',
    type:'info'
  },
  {
    content: '到岗试工',
    timestamp: '2018-04-03 20:46',
    type:'info'
  },
  {
    content: '正式入职',
    timestamp: '2018-04-12 20:46',
    type:'info'
  }
]);
// 监听后端状态变化，更新活动列表
watch(backendStatus, (newStatus) => {
  // 重置所有状态为普通
  activities.value.forEach(item => {
    item.type = 'info';
  });

  // 根据新状态高亮对应节点
  if (newStatus >= 0 && newStatus < statusConfig.length) {
    const targetActivity = activities.value.find(
        item => item.content === statusConfig[newStatus].content
    );
    if (targetActivity) {
      targetActivity.type = statusConfig[newStatus].type;
    }
  }
});





/*companyLogo: '/imgs/companyLogo.png',
    contactAvatar: '/imgs/contactAvatar.png',// 实际替换为联系人头像地址
    applyButtonText: '应聘记录',*/
// 定义加载特定岗位的方法
const loadJob = ()=>{
  let userId = user.value.id;
  axios.get('http://localhost:9099/interestedJobs/selectBm/'+userId+'/'+getJobId())
      .then(response => {
        if(response.data.state===200){
          console.log(response.data.data[0]);
          myJob.value = response.data.data[0];
          // myJob.value.applyButtonText = '应聘记录';
          myJob.value.companyLogo = '/imgs/companyLogo.png';
          myJob.value.contactAvatar = '/imgs/contactAvatar.png';
          backendStatus.value=response.data.data[0].state;
        }else{
          ElMessage.error(response.data.message);
        }
      })
}

// 一进入页面就立即加载岗位列表
onMounted(() => {
  loadJob();
})
// 数据部分
const helpLinks = ref([
  { title: '常见问题', url: '/faq' },
  { title: '用户协议', url: '/terms' },
  { title: '隐私政策', url: '/privacy' },
  { title: '售后服务', url: '/support' }
])
const contactInfo = ref(
    {phone: '400-123-4567',
      email: 'support@yourcompany.com',
      address: '北京市朝阳区科技大厦12层'}
);
const qrCodes = ref([      {
  title: '微信公众号',
  image: new URL('@/assets/qr-wechat.png', import.meta.url).href
  // image: require('@/assets/qr-wechat.png')
},
  {
    title: '小程序码',
    image: new URL('@/assets/qr-miniprogram.png', import.meta.url).href
    // image: require('@/assets/qr-miniprogram.png')
  }
])


</script>
<style scoped>
.menu-link {
  color:  #000;
  font-weight: bold;
  margin-right: 10px;
  text-decoration: none;
  padding-top: 8px;
  padding-left:60px;
}
/* 关键样式 */
.page-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.fixed-header {
  position: fixed !important; /* 固定定位 */
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000; /* 确保在最上层 */
  background: white; /* 添加背景色避免透明 */
  box-shadow: 0 2px 12px rgba(0,0,0,0.1); /* 可选：添加阴影增强层次感 */
}

.scroll-container {
  flex: 1;
  overflow-y: auto;
  margin-top: 60px; /* 需要等于 header 高度 */
}

/* 样式部分 */
.custom-footer {
  position: static !important; /* 关闭固定定位 */
  background-color: #f8f9fa;
  padding: 40px 20px;
  color: #666;
}

.footer-section {
  margin-bottom: 30px;
  padding: 0 20px;
}

.footer-title {
  font-size: 16px;
  color: #333;
  margin-bottom: 15px;
  font-weight: bold;
  padding-left: 10px;
  border-left: 4px solid #409EFF; /* 左侧装饰线 */
}

.help-list {
  list-style: none;
  padding-left: 0;
}

.help-list li {
  margin-bottom: 10px;
}

.contact-info p {
  margin: 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.qr-codes {
  text-align: center;
}

.qr-image {
  width: 120px;
  height: 120px;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 5px;
  background: white;
}

.qr-desc {
  margin-top: 8px;
  font-size: 12px;
  color: #999;
}

.copyright {
  text-align: center;
  margin-top: 40px;
  font-size: 12px;
  color: #999;
}

.footer-divider {
  border: 0;
  border-top: 1px solid #e4e7ed;
  margin: 20px 0;
}


.job-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px;
  border: 1px solid #eee;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  width: 50%;
  margin: 0 auto;
  margin-top: 20px;
}
.job-info {
  flex: 1 1 50%; /* 修改为固定占据50%宽度，同时允许收缩 */
  padding-top: 10px;
  padding-right: 8px; /* 调整内边距代替原来的margin-right */
  padding-left: 20px;
}
/*.company-info {
  flex: 1 1 50%; !* 修改为固定占据50%宽度，同时允许收缩 *!
  padding-left: 8px; !* 添加左侧内边距，保持两侧平衡 *!
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}*/
.company-info {
  padding-top: 10px;
  flex: 1 1 50%;
  padding-left: 8px;
  display: flex;
  /* 改为水平排列，子元素同一行显示 */
  flex-direction: row;
  /* 垂直方向居中对齐，可根据需求调整 */
  align-items: center;
  /* 若子元素超出宽度，可设置换行，根据需求决定是否添加 */
  flex-wrap: wrap;
}
.job-title {
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 8px 0;
  text-align: left; /* 文本内容居中 */
}
.salary_range {
  color: #ff9900;
  font-size: 16px;
  margin: 0 0 4px 0;
  text-align: left; /* 文本内容靠左 */
}
.experience {
  color: #999;
  margin: 0 0 8px 0;
  text-align: left; /* 文本内容居中 */
}
.welfare-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px 0;
  display: flex;
  gap: 8px;
}
.welfare-list li {
  background-color: #f5f5f5;
  padding: 4px 8px;
  border-radius: 4px;
  color: #666;
}
.publish-info {
  display: flex;
  align-items: center;
  color: #999;
}
.postTime{
  background-color: #f5f5f5;
  padding: 4px 8px ;
  border-radius: 4px;
  margin-right: 8px;
  margin-left: 4px;
}
/*.company-logo {
  width: 120px;
  height: 120px;
  border-radius: 4px;
  margin-bottom: 8px;
}*/
.company-logo {
  width: 120px;
  height: 120px;
  border-radius: 4px;
  /* 让 logo 占容器宽度的 30% */
  flex: 0 0 30%;
  /* 去掉底部 margin，因为现在是水平排列 */
  margin-bottom: 0;
  /* 可根据需求设置右侧 margin，隔开与其他内容的距离 */
  margin-right: 10px;
}
.company-detail {
  /* 占剩余空间的 70% */
  flex: 1;
  display: flex;
  flex-direction: column;
  /* 若需要垂直居中，可加这个，根据需求调整 */
  /* justify-content: center; */
}
.company-name {
  font-size: 16px;
  font-weight: bold;
  margin: 0 0 4px 0;
  text-align: left; /* 文本内容靠左 */
}
.industry {
  text-align: left; /* 文本内容靠左 */
  color: #999;
  margin: 0 0 8px 0;
}
.contact-info {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}
.contact-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 8px;
}
.contact-name {
  margin-right: 8px;
}
.contact-phone {
  color: #999;
}
/*.apply-button {
  margin-left: auto; !* 将按钮推到右侧 *!
  !* 保持原有样式 *!
  background-color: #007bff;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
.apply-button:hover {
  background-color: #0056b3;
}*/
</style>

